package com.management.controller;

import com.management.dao.UserAndCompanyDao;
import com.management.po.User;
import com.management.po.UserAndCompany;
import com.management.service.UserAndCompanyService;
import com.management.service.UserService;
import com.management.vo.UserAndCompanyVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * @author XS
 * 公司人员表控制器
 * @version 1.0
 */
@Controller
@RequestMapping("/userandcompany")
public class UserAndCompanyController {
    Logger logger = Logger.getLogger(UserAndCompanyController.class);
    @Autowired
    UserAndCompanyDao userAndCompanyDao;
    @Autowired
    UserService userService;
    @Autowired
    UserAndCompanyService userAndCompanyService;
    //展示信息
    @RequestMapping("/userandcompanylist")
    public String Userandcompany(int userId, Model model, HttpSession session){
        logger.info("进入控制器");
        List<UserAndCompanyVO> list = userAndCompanyDao.findByUserId(userId);
        User user = userService.findByUserId(userId);
        logger.debug(user);
        logger.debug(user.getUserName());
        logger.debug(list);
        if(list!=null){
            session.setAttribute("user",user);
            model.addAttribute("list",list);
            return "logininfo";
        }else {
            return "logininfo" ;
        }
    }

    // 进入后台管理页面
    @RequestMapping("/main")
    public String main(int userAndCompanyId,HttpSession session){
        logger.info("进入后台管理控制器");
        logger.info(userAndCompanyId);
       UserAndCompanyVO userAndCompanyVO = userAndCompanyService.findByUserAndCompanyId(userAndCompanyId);
       session.setAttribute("userAndCompanyVO",userAndCompanyVO);
       return "main";
    }
}
